package org.algorithm.BinarySearch;

public class FindEdgeIndex {

    public static void main(String[] args) {
        int [] nums = {1,2,2,2,3,6,7};
        int rightEdge = findLeftEdge(nums, 5);
        System.out.println(rightEdge);
    }


    private static int findLeftEdge(int []nums,int target){
        int left =0;
        int right = nums.length-1;
        while (left<=right){
            int mid =(left+right)>>>1;
            if (target<=nums[mid]){
                right=mid-1;
            }else {
                left=mid+1;
            }
        }

        return left;
    }

    private static int findRightEdge(int [] nums,int target){
        int left =0;
        int right =nums.length-1;

        while (left<=right){
            int mid =(left+right)>>>1;
            if (nums[mid]<=target){
                left =mid+1;
            }else {
                right=mid-1;
            }
        }

        return right;
    }
}
